Letter to digit
In [1]:
print("ACGT".index("C"))
d={"A":0,"C":1,"G":2,"T":3}
print(d)
In [2]:
d2={}
for i,l in enumerate("ACGT"):
print(i, l)
d2[l]=i
print(d2)
In [3]:
#dict([("A",0),("C",1)...])
d3=dict( ((l,i) for i,l in enumerate("ACGT")) )
print(d3)
Power operator
In [4]:
print(4**3)
In [5]:
for p,d in enumerate("ACGTCAGAC"[::-1]):
print("Digit",d,"power",p)
In [6]:
print([0]*22)
d1={}
d2=d1
#Careful! This does not create 22 dictionaries, it creates a list
#with 22 pointers to the exact same dictionary
lst=[{}]*22
print(lst)
lst[0]["k"]="v" #All of them will change!
print(lst)
#This is a way to create 22 dictionaries
lst=[{} for _ in range(22)]
print(lst)
lst[0]["k"]="v"
print(lst)
In [7]:
print([[0]*10 for _ in range(10)])
In [8]:
#Just a reminder, nothing else
spectrum=[0]*64
spectrum[5]=54656
spectrum[5]+=1
In [9]:
counter={}
for l in "hfjdskohgfjlkdsahfjlsahfjlksa":
counter[l]=counter.get(l,0)+1
print(counter)
In [ ]: